package com.cn.qtms.common.tree;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @Name:Tree
 * @Description: 树形结构类 处理资源部门等结构问题
 * @Author: Neil
 * @Date: 2019-08-27 16:58
 **/
@Getter
@Setter
@NoArgsConstructor
public class Tree<T> {
    /**
     * 节点ID
     */
    private String id;
    /**
     * 显示节点文本
     */
    private String title;
    /**
     * 节点状态，open closed
     */
    private Map<String, Object> state;
    /**
     * 节点是否被选中 true false
     */
    private boolean checked = false;
    /**
     * 节点属性
     */
    private Map<String, Object> meta;

    /**
     * 节点的子节点
     */
    private List<Tree<T>> children = new ArrayList<Tree<T>>();

    /**
     * 父ID
     */
    private String parentId;
    /**
     * 是否有父节点
     */
    private boolean hasParent = false;
    /**
     * 是否有子节点
     */
    private boolean hasChildren = false;

    //====== 后添加属性适用于菜单 -add by zhangyang
    /**
     * 是否叶节点
     */
    private Boolean isLeaf;
    /**
     * 类型
     */
    private String resType;
    /**
     * url
     */
    private String path;
    /**
     * 铭恒
     */
    private String name;
    /**
     * 图标
     */
    private String icon;
    /**
     * 存在
     */
    private Boolean exact;

    private String rescode;
    //====== 后添加属性 结束

    public Tree(String key, String text, Map<String, Object> state, boolean checked, Map<String, Object> attributes,
                List<Tree<T>> children, boolean isParent, boolean isChildren, String parentId, String rescode) {
        super();
        this.id = id;
        this.title = text;
        this.state = state;
        this.checked = checked;
        this.meta = attributes;
        this.children = children;
        this.hasParent = isParent;
        this.hasChildren = isChildren;
        this.parentId = parentId;
        this.rescode = rescode;
    }

    @Override
    public String toString() {
        return "Tree{" +
                "id='" + id + '\'' +
                ", title='" + title + '\'' +
                ", state=" + state +
                ", checked=" + checked +
                ", meta=" + meta +
                ", children=" + children +
                ", parentId='" + parentId + '\'' +
                ", hasParent=" + hasParent +
                ", hasChildren=" + hasChildren +
                '}';
    }
}